<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Random;
use think\Config;
use think\Validate;

/**
 * 团队接口
 */
class Team extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = [''];

    public function _initialize()
    {
        parent::_initialize();

        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }
        $this->department=model('admin/Department');
        $this->user=model('admin/User');
    }

    /**
     * 部门管理
     */
    public function department(){
       $this->success('OK',$this->department->order('order desc')->select());
    }

    /**我的团队
     * @param int $page
     * @param int $limit
     * @param null $keywords
     * @param null $department_id
     */
    public  function myteamsList($page=1,$limit=10,$keywords=null,$department_id=null){
    $where['id']=['<>',$this->auth->id];
    $where1="";
    if($keywords!=null){
        $where['username']=['like',"%".$keywords."%"];
    }
    if($department_id!=null){
        $where1=" FIND_IN_SET('$department_id',department_ids)";
    }

   $userList= $this->user->where($where)->where($where1)->field('id,username,avatar')
        ->paginate($limit);

    $this->success('OK',$userList);

    }





}
